package com.wm.service.imp;

import java.util.List;

import com.wm.bean.User;
import com.wm.bean.UserComment;
import com.wm.dao.AddressDAO;
import com.wm.dao.UserCommentDAO;
import com.wm.dao.UserDAO;
import com.wm.service.UserCommentService;
import com.wm.service.UserService;
import com.wm.service.web.PageList;
import com.wm.service.web.Pages;

/**
 * @author yangbo
 *
 * 2013-1-4
 */
public class UserCommentServiceImp implements UserCommentService {
	
	private UserCommentDAO userCommentDAO;
	private UserDAO userDAO;
	
	public UserCommentDAO getUserCommentDAO() {
		return userCommentDAO;
	}

	public void setUserCommentDAO(UserCommentDAO userCommentDAO) {
		this.userCommentDAO = userCommentDAO;
	}
	public UserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	/**
	 * 保存UserComment对象
	 * 
	 * @param uc
	 * 			UserComment
	 * @return  UserComment
	 * 			UserComment
	 */
	public UserComment saveUserComment(UserComment uc){
		uc = this.getUserCommentDAO().saveUserComment(uc);
		return uc;
	}
	
	/**
	 * 更新UserComment对象
	 * 
	 * @param uc
	 * 			UserComment
	 * @return  UserComment
	 * 			UserComment
	 */
	public UserComment updateUserComment(UserComment uc){
		uc = this.getUserCommentDAO().updateUserComment(uc);
		return uc;
	}
	
	/**
	 * 根据ID删除UserComment对象
	 * 
	 * @param id
	 * 			long
	 */
	public void removeUserCommentById(long id){
		this.getUserCommentDAO().removeUserCommentById(id);
	}
	
	/**
	 * 根据ID获取UserComment对象
	 * 
	 * @param id
	 * 			long
	 * @return  UserComment
	 * 			UserComment
	 */
	public UserComment findUserCommentById(long id){
		return this.getUserCommentDAO().findUserCommentById(id);
	}
	
	
	/**
	 * 获取UserComment对象列表
	 * 
	 * @param orderby
	 *            String
	 * @param ascOrDesc
	 *            int
	 * @param pages
	 * 			  Pages
	 * @return PageList
	 * 			UserComment对象列表
	 */
	public PageList findUserComments(String orderby, int ascOrDesc,Pages pages){
		PageList pl = new PageList();
        if (pages.getTotalNum() == -1) {
            pages.setTotalNum(this.getUserCommentDAO().getUserCommentNum());
        }
        pages.executeCount();
        if(pages.getTotalNum() == 0){
        	pl.setObjectList(null);
        	pl.setPages(pages);
        	return pl;
        }
		List l = this.getUserCommentDAO().findUserComments(orderby, ascOrDesc,pages.getSpage(), pages.getPerPageNum());
		if(l == null || l.isEmpty()){
	   		 pl.setObjectList(null);
	   	     pl.setPages(pages);
	   		 return pl;
		}else{
			for(int i=0;i<l.size();i++){
				UserComment uc = (UserComment) l.get(i);
				uc.setUser(this.getUserDAO().findUserById(uc.getUserId()));
			}
			pl.setObjectList(l);
	        pl.setPages(pages);
	        return pl;
		}
	}
	
	/**
	 * 根据userId获取UserComment对象列表
	 * @param userId
	 * @return
	 */
	public List findUserCommentByUserId(long userId){
		return this.getUserCommentDAO().findUserCommentByUserId(userId);
	}
}
